/// ------------------------------------------------------------------------------------------------------------------------------------
///
/// MIT License
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all
/// copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
/// SOFTWARE.
///
/// Copyright (c) 2024 ycz. All rights reserved.
///
/// Created by ycz on 24-11-7.
///
/// @file  app_uart.h
///
/// @brief
///     应用层 串口配置 API
///
/// ------------------------------------------------------------------------------------------------------------------------------------



/// ------------------------------------------------------------------------------------------------------------------------------------
/// 防止当前头文件被重复引用
/// ------------------------------------------------------------------------------------------------------------------------------------

#ifndef _APP_UART_H
#define _APP_UART_H



/// ------------------------------------------------------------------------------------------------------------------------------------
/// 头文件
/// ------------------------------------------------------------------------------------------------------------------------------------

#include <stdint.h>
#include <stdbool.h>



/// ------------------------------------------------------------------------------------------------------------------------------------
/// 兼容 c++
/// ------------------------------------------------------------------------------------------------------------------------------------

#ifdef __cplusplus
extern "C" {
#endif



/// ------------------------------------------------------------------------------------------------------------------------------------
/// 宏定义
/// ------------------------------------------------------------------------------------------------------------------------------------

#define APP_UART_MAJOR 0  ///< 主版本     ( 主架构变化 )
#define APP_UART_MINOR 1  ///< 次版本     ( 单个功能增加或修改 )
#define APP_UART_PATCH 0  ///< 补丁版本   ( bug 修复 )



/// ------------------------------------------------------------------------------------------------------------------------------------
/// 枚举
/// ------------------------------------------------------------------------------------------------------------------------------------

/// 串口枚举
typedef enum {
    UART_1 = 1,  ///< 串口 1
    UART_2,      ///< 串口 2
    UART_3,      ///< 串口 3
    UART_4,      ///< 串口 4
    UART_5,      ///< 串口 5
    UART_6,      ///< 串口 6
} UART_NUM_e;



/// ------------------------------------------------------------------------------------------------------------------------------------
/// 结构体
/// ------------------------------------------------------------------------------------------------------------------------------------

/// 串口配置结构体
typedef struct {
    uint32_t baudrate_1;  ///< 波特率 串口 1
    uint32_t baudrate_2;  ///< 波特率 串口 2
    uint32_t baudrate_3;  ///< 波特率 串口 3
    uint32_t baudrate_4;  ///< 波特率 串口 4
    uint32_t baudrate_5;  ///< 波特率 串口 5
    uint32_t baudrate_6;  ///< 波特率 串口 6
} APP_UART_CONFIG_st;



/// ------------------------------------------------------------------------------------------------------------------------------------
/// 函数 API
/// ------------------------------------------------------------------------------------------------------------------------------------

void                app_uart_print_version();                                          ///< 打印模块版本号
void                app_uart_irq_cb(UART_NUM_e uart_num);                              ///< 串口中断回调处理
bool                app_uart_send(UART_NUM_e uart_num, uint8_t *data, uint16_t size);  ///< 串口发送数据
uint32_t            app_uart_get_baudrate(UART_NUM_e uart_num);                        ///< 获取串口波特率
bool                app_uart_set_baudrate(UART_NUM_e uart_num, uint32_t baudrate);     ///< 设置串口波特率
void                app_uart_config_print(APP_UART_CONFIG_st *config);                 ///< 打印参数
APP_UART_CONFIG_st *app_uart_config_get();                                             ///< 获取参数
bool                app_uart_config_set(APP_UART_CONFIG_st *config);                   ///< 设置参数
bool                app_uart_init();                                                   ///< 初始化



/// ------------------------------------------------------------------------------------------------------------------------------------
/// 条件编译结尾
/// ------------------------------------------------------------------------------------------------------------------------------------

#ifdef __cplusplus
}
#endif  // __cplusplus 兼容 c++
#endif  // _APP_UART_H 防止当前头文件被重复引用